<template>
	<view class="body">
		<view v-for="item in goodsList" :key="item.id" class="goods_item">
			<view>
				<image :src="item.imgUrl"></image>
			</view>
			<!-- 鸽蛋 -->
			<view v-if="goodsType == 0" class="message">
				<view>下蛋时间:{{item.layTime}}</view>
			</view>
			<!-- 鸽子 -->
			<view v-else class="message">
				<view>类型:{{item.ageGroup}}</view>
				<view>年龄:{{item.age}}</view>
			</view>
		</view>
		<view>
			<u--form labelPosition="left" :model="dataForm" :rules="dataRule">
				<u-form-item label="价格" prop="dataForm.price">
					<u--input placeholder="请设置价格" border="surround" v-model="dataForm.price"></u--input>
				</u-form-item>
			</u--form>
		</view>
		<view class="submitButton">
			<u-button type="primary" size="small" text="提交" @click="submit"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['ids', 'catagoryId', 'goodsList','goodsType'],
		data() {
			return {
				dataForm: {
					number: 1,
					price: 0,
					catagoryId:4,
					ids: []	
				},
				dataRule: {
					price: {
						required: true
					}
				}
			}
		},
		methods: {
			// 上架商品
			async submit() {
				this.dataForm.number = this.goodsList.length;
				this.dataForm.catagoryId = this.catagoryId;
				this.dataForm.ids = this.ids;
				const res = await this.$myRequest({
					url: 'shop/applet/put',
					method: 'post',
					data: this.dataForm
				})
				//刷新列表数据
				this.$emit('refreshList');
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body {
		padding: 50rpx;
		width: 500rpx;
		height: 500rpx;
	}

	.goods_item {
		display: flex;
		font-size: 30rpx;

		image {
			margin-right: 20rpx;
			border-radius: 50rpx;
			width: 100rpx;
			height: 100rpx;
		}
	}

	.submitButton {
		width:300rpx;
		margin-top: 50rpx;
	}
</style>
